import pymysql

db = pymysql.connect(host="114.115.160.16", user="root", password="123456Aa!", database="fund")
cursor = db.cursor()

sql = "select fund_id from api_fund"
cursor.execute(sql)
funds = cursor.fetchall()


sql = "select openid from api_user"
cursor.execute(sql)
users = cursor.fetchall()

cursor.execute("select max(id) from api_userfundscore")
id_now = cursor.fetchall()[0][0]
if id_now == None:
    id_now = 0

'''for fund in funds:
    for user in users:
        sql = "select * from api_userfundscore where user_id='{}' and fund_id='{}'".format(user[0], fund[0])
        cursor.execute(sql)
        score_now = cursor.fetchall()
        if len(score_now) == 0:
            id_now += 1
            sql = "insert into api_userfundscore values({}, '{}', '{}', 0, 0)".format(id_now, user[0], fund[0])
            cursor.execute(sql)
            db.commit()'''

for user in users:
    sql = "select * from api_userfundscore where user_id='{}'".format(user[0])
    cursor.execute(sql)
    score_now = cursor.fetchall()
    if len(score_now) == 0:
        for fund in funds:
            id_now += 1
            sql = "insert into api_userfundscore values({}, '{}', '{}', 0, 0)".format(id_now, user[0], fund[0])
            cursor.execute(sql)
            db.commit()
            print(fund[0])
